/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package clip.net;

import java.io.File;
import java.io.Serializable;
import java.util.Random;

/**
 *
 * @author admin
 */
public class FileInfo implements Serializable {
    
    private String filename;
    private String description;
    private long size;
    private String downloadToken;
    
    public FileInfo(String filename, String description, long size) {
        this.filename = filename;
        this.description = description;
        this.size = size;
    }

    public static FileInfo createFileInfo(File f) {
        return new FileInfo(f.getName(),"",f.length());
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getFilename() {
        return filename;
    }

    public long getSize() {
        return size;
    }
    
    
    public void assignRandomToken() {
        this.downloadToken=createRandomToken();
    }
    
    public static String createRandomToken() {
        final int TOKENLENGTH=23;
        final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
        StringBuffer sb=new StringBuffer();
        Random r=new Random();
        for (int i = 0; i < TOKENLENGTH; i++) {
            sb.append(CHARACTERS.charAt(r.nextInt(CHARACTERS.length())));
        }
        return sb.toString();
    }
    
    public static void main(String[] args) {
        System.out.println(createRandomToken());
    }
}
